//This prototype is provided by the Mozilla foundation and
//is distributed under the MIT license.
//http://www.ibiblio.org/pub/Linux/LICENSES/mit.license

if (!Array.prototype.indexOf)
{
  Array.prototype.indexOf = function(elt /*, from*/)
  {
    var len = this.length;

    var from = Number(arguments[1]) || 0;
    from = (from < 0)
         ? Math.ceil(from)
         : Math.floor(from);
    if (from < 0)
      from += len;

    for (; from < len; from++)
    {
      if (from in this &&
          this[from] === elt)
        return from;
    }
    return -1;
  };
}

  function setInPoint() {

    var flash = (navigator.appName.indexOf("Microsoft") != -1) ? window.videoplayer_swf : window.document.videoplayer_swf;
    var nTime = flash.flashGetCurrentTime();
    document.forms["sceneform"].inpoint.value = nTime;

  }

  function setOutPoint() {

    var flash = (navigator.appName.indexOf("Microsoft") != -1) ? window.videoplayer_swf : window.document.videoplayer_swf;
    var nTime = flash.flashGetCurrentTime();
    document.forms["sceneform"].outpoint.value = nTime;

  }

  function seek(nSeconds) {

    var flash = (navigator.appName.indexOf("Microsoft") != -1) ? window.videoplayer_swf : window.document.videoplayer_swf;
    var b = flash.flashSeek(nSeconds);

  }


  function videoFullscreen(sDcId, sPlayFromTime) {

    var sProperties = 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=no,resizable=yes';
    var iWidth      = screen.availWidth - 120;
    var iHeight     = screen.availHeight - 220;
    var iLeft       = (screen.availWidth - iWidth) / 2;
    var iTop        = (screen.availHeight - iHeight) / 2;
    var sProperties = 'height=' + iHeight + ',width=' + iWidth + ',top=' + iTop + ',left=' + iLeft + ',' + sProperties;
    var oWin        = window.open('index2.php?popup=video&dc_id=' + sDcId + '&playfromtime=' + sPlayFromTime + '&fullscreen=1', 'window_video', sProperties);
    if(!oWin) {
      alert('Het videovenster kon niet worden geopend, waarschijnlijk door een popup-blocker.\n');
    } else {
      oWin.focus();
    }
    
  }



function toggleHelp () {
  
  var oLink = document.getElementById('help_a');
  var oDiv = document.getElementById('help_div');
  if(oDiv.style.display == 'none') {
    oDiv.style.display = '';
    oLink.innerHTML = 'toelichting verbergen';
  } else {
    oDiv.style.display = 'none';
    oLink.innerHTML = 'toelichting';
  }
  
}



function tabResultCount(sAantalFotos, sAantalFilms, sAantalScenes) {
  
  var oLinkFoto   = parent.header.document.getElementById('submenu_link_3_0');
  var oLinkFilm   = parent.header.document.getElementById('submenu_link_3_1');
  var oLinkScene  = parent.header.document.getElementById('submenu_link_3_2');

  oLinkFoto.innerHTML   = 'Foto\'s (' + sAantalFotos + ')';
  oLinkFilm.innerHTML   = 'Films (' + sAantalFilms + ')';
  oLinkScene.innerHTML  = 'Scènes (' + sAantalScenes + ')';
  
}

function popWin(URL, width, height) {
    var LeftPosition=(screen.width)?(screen.width-width)/2:100;
    var TopPosition=(screen.height)?(screen.height-height)/2:100;
    var PopUpWin = window.open(URL,'WindowWithoutButtons', 'height='+height+',width='+width+',top='+TopPosition+',left='+LeftPosition+',toolbar=0,status=0,menubar=0,scrollbars=1,resizable=1');
    PopUpWin.focus()
    PopUpWin.opener.name = 'opener';
}

function toonIndex (veld )
{
    url='./index2.php?popup=toonIndex&dc=' + veld
    popWin(url,600,400)
}

function goKring(kr_id)
{
document.location='./?Kring='+kr_id
}

function writeComment (dc_id, ge_id )
{
    url='./index2.php?popup=commentaar&dc_id=' + dc_id
    popWin(url,600,400)
}

function readComment (dc_id )
{
    url='./index2.php?popup=reactie&dc_id=' + dc_id
    popWin(url,600,400)
}

function addCart (dc_id )
{
    url='./index2.php?popup=winkelwagen&dc_id=' + dc_id
    popWin(url,600,400)
}

function topView (dc_id )
{
    url='./index2.php?popup=topview&nomargin=1&dc_id=' + dc_id
    //popWin(url,640,480)
    popWin(url,600,400)
}

function uitIndex(veld,waarde)
{
    if ( veld.match(/[0-9]+/) ) veld='ve_114_'+veld
    opener.document.forms['uitgebreidZoeken']['s['+veld+']'].value = '"'+waarde+'"'
    self.close()
}

function bookmarkAdd(dc_id, ge_id, me_key)
{
    url='./index2.php?popup=bookmark_' + me_key +'&dc_id=' + dc_id;
    if ( ge_id==0)
        popWin(url,600,400)
    else
        popWin(url,600,150)
}

function setHeight()
{
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  document.getElementById('maincontent').style.height=myHeight-153;
}


/* thanks to ppk */
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


